﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Description;

namespace Pg.BioMedics.SDR.ServiceAgents
{
    /// <summary>
    /// Security strategy connected directly to basic / realm 
    /// authnetication strategy. This strategy applies user name and 
    /// password to service credetnails object
    /// </summary>
    internal class BasicSecurityStrategy : ISecurityStrategy
    {
        #region Fields

        private string userName;
        private string password;

        #endregion

        #region Constructors

        /// <summary>
        /// Creates instance of basic security strategy for given 
        /// user name nad password
        /// </summary>
        /// <param name="userName">User name</param>
        /// <param name="password">Password</param>
        internal BasicSecurityStrategy(string userName, string password)
        {
            this.userName = userName;
            this.password = password;
        }

        #endregion

        #region ISecurityStrategy Members

        /// <summary>
        /// Applies basic authentication credentials to 
        /// the connection with remote service
        /// </summary>
        /// <param name="credentials"></param>
        public void ApplyCredentials(ClientCredentials credentials)
        {
            credentials.UserName.UserName = this.userName;
            credentials.UserName.Password = this.password; 
        }

        #endregion
    }
}
